package com.cjh.mybatis08.type;

import lombok.AllArgsConstructor;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

/**
 * @Descripton jdbc类型枚举
 * @Author cjh
 * @Date 2023/5/29 10:43
 */
@AllArgsConstructor
public enum JdbcType {
    INTEGER(Types.INTEGER),
    FLOAT(Types.FLOAT),
    DOUBLE(Types.DOUBLE),
    DECIMAL(Types.DECIMAL),
    VARCHAR(Types.VARCHAR),
    TIMESTAMP(Types.TIMESTAMP);
    public final int TYPE_CODE;
    private static Map<Integer,JdbcType> codeLookup  =new HashMap<>();
    static {
        for (JdbcType type : JdbcType.values()) {
            codeLookup.put(type.TYPE_CODE,type);
        }
    }

    public static JdbcType forCode(int code){
        return codeLookup.get(code);
    }
}
